<template>
  <div id="app">
    <h2>购物车</h2>
    <div v-for="item in cartItems" :key="item.id">
      {{ item.name }} - ¥{{ item.price }} - 数量：{{ item.quantity }}
      <button @click="increment(item)">+</button>
      <button @click="decrement(item)">-</button>
    </div>
    <p>总价：¥{{ total }}</p>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'; // 添加导入

export default {
  name: 'App',
  computed: {
    ...mapState(['cartItems', 'total']) // 使用 mapState
  },
  methods: {
    ...mapMutations(['increment', 'decrement']) // 使用 mapMutations
  }
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

</style>